import axios from 'axios'
import { Notify } from 'vant';

// 创建 axios 实例
const service = axios.create({
  timeout: 20000 // 请求超时时间
})
const service2 = axios.create({
  timeout: 20000, // 请求超时时间,
  headers: {
    'Content-Type': 'multipart/form-data;boundary = ' + new Date().getTime(),
  },
})

const err = (error) => {
  if (error.response) {
    let data = error.response.data

    switch (error.response.status) {
      case 403:
        Notify({ message: '系统提示拒绝访问',type:'danger',duration: 1500})
        break
      case 500:
       // Notify({ message: '系统提示Token失效，请重新登录!',type:'danger',duration: 1500})
        break
      case 404:
        Notify({ message: '系统提示很抱歉，资源未找到!',type:'danger',duration: 1500})
        break
      case 504:
        Notify({ message: '系统提示网络超时'})
        break
      case 401:
        Notify({ message: '系统提示未授权，请重新登录',type:'danger',duration: 1500})
        break
      default:
        Notify({
          message: '系统提示'+data.message,
          type:'danger',duration: 1500
        })
        break
    }
  }
  return Promise.reject(error)
};
service.interceptors.request.use(config => {
  return config
},(error) => {
  return Promise.reject(error)
})

// response interceptor
service.interceptors.response.use((response) => {
  return response.data
}, err)

export {
  service as axios,
    service2 as axios2
}